<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>请求方法</title>
</head>

<body>
    <button>注册</button>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        //get 获取数据  post提交数据   put  delete  patch
        //axios 请求配置
        document.querySelector('button').addEventListener('click', () => {
            axios({
                url: 'http://hmajax.itheima.net/api/register',
                method: 'post',
                data: {
                    username: 'sjyao123',
                    password: '123456'
                }
            }).then(result => {
                console.log(result);
                //处理错误信息
            }).catch(error => {
                console.log(error);
                console.log(error.response.data.message);
                alert(error.response.data.message);
            })
        })









    </script>
</body>

</html>